package com.lovo.homework7_8GameOfRockPaperScissors;

import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.regex.Pattern;

public class RegularExpression {
    public static boolean flagName = false;
    public static boolean flagPassWord = false;
    public static boolean flagRePassWord = false;
    public static String userPassword ;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        for (int i = 1; i <2 ; i++) {
            System.out.println("请输入用户名，要求6-20位字母、数字、下划线组成");
            String userName= scan.next();
            Pattern pattern1 =Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$)(?![_-]+$)[0-9a-zA-Z_]{6,20}$");//^(?=.*[_])(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9_]{6,}$
            if (pattern1.matcher(userName).matches()){
                    flagName=true;
            }else {
                System.out.println("错误输入");
                i--;
            }
            if (flagName){
                for (int j = 0; j < 1; j++) {
                    System.out.println("请输入密码，要求必须包含大小写字母和数字的组合，不能使用特殊字符，长度不少于6位");
                    userPassword = scan.next();
                    Pattern pattern2 = Pattern.compile("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$");
                    if (pattern2.matcher(userPassword).matches()){
                        flagPassWord=true;
                    }else {
                        System.out.println("错误输入");
                        j--;
                    }
                }
            }
            if (flagPassWord){
                for (int j = 0; j < 1; j++) {
                    System.out.println(" 输入确认密码，要求和密码一致");
                    String userRePassword = scan.next();
                    if (userRePassword.equals(userPassword)){
                        flagRePassWord=true;
                    }else {
                        System.out.println("错误输入");
                        j--;
                    }
                }
            }
            if (flagRePassWord){
                for (int j = 0; j < 1; j++) {
                    System.out.println("输入邮箱");
                    String email = scan.next();
                    Pattern pattern3 =Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
                    if (pattern3.matcher(email).matches()){
                        System.out.println("成功");
                    }else {
                        System.out.println("错误输入");
                        j--;
                    }
                }
            }
        }
    }
}
